﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ScreenRuler
{
    public partial class RatioCalculator : Form
    {
        public RatioCalculator()
        {
            InitializeComponent();
        }

        private void btnDetectScreenResolution_Click(object sender, EventArgs e)
        {
            Size ScreenArea = Screen.PrimaryScreen.Bounds.Size;
            this.cbWidth.Text = ScreenArea.Width.ToString();
            this.cbHeight.Text = ScreenArea.Height.ToString();
        }

        public double LengthInMMPerPixel { get; set; }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                int ScreenWidth = int.Parse(this.cbWidth.Text.Trim());
                int ScreenHeight = int.Parse(this.cbHeight.Text.Trim());
                double ScreenSizeInMM = double.Parse(this.cbScreenSizeInInch.Text.Trim())*25.4;
                this.LengthInMMPerPixel = ScreenSizeInMM /
                    Math.Pow(Math.Pow(ScreenWidth, 2) + Math.Pow(ScreenHeight, 2), 0.5);
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }
    }
}
